package gui;

import javax.swing.JLayeredPane;

import gui.event.*;

import dal.MapStruct;

//Here will we edit the map's lookout
public class MapEditor extends MainPanel{

	private static final long serialVersionUID = 1L;
	private SidePanel sidePanel;
	private MapViewPort mvp;
	private MainPanel prev;
	
	public void setPrevious(MainPanel prev){
		this.prev = prev;
	}
	
	public MainPanel getPrevious(){
		return prev;
	}
	
	public MapViewPort getViewPort(){
		return this.mvp;
	}
	
	public void setMapStruct(MapStruct ms){
		LayeredPane layers = new LayeredPane(ms);
		JLayeredPane lp = layers.getJLayeredPane();
		
		HexGrid grid = new HexGrid(ms);
		HexGridListener hgl = new HexGridListener(grid, lp, sidePanel.getTypeList());
		hgl.setFocusObject(mvp);
		HexGridMotionListener hgml = new HexGridMotionListener(grid, lp, sidePanel.getTypeList());
		hgml.setMouseListener(hgl);
		lp.addMouseListener(hgl);
		lp.addMouseMotionListener(hgml);
		
		sidePanel.setLayers(lp);
		sidePanel.setMapStruct(ms);
		mvp.setView(layers);
		sidePanel.setMapViewPort(mvp);
	}
	
	// Default constructor for this class
	public MapEditor() {
		sidePanel = new SidePanel(this);
		add(sidePanel);

		mvp = new MapViewPort();
		mvp.setLocation(sidePanel.getWidth(), 0);
		mvp.setSize(this.getWidth() - sidePanel.getWidth(), this.getHeight());
		add(mvp);
	}
}